<!--   
Persistent Digital Archives and Library System (PeDALS) 
(c) 2011 - All Rights Reserved
//-->
<?php 
include 'includes\config.php'; 
$term = urldecode(@$_GET["ser"]);
if ($term == "") {
echo "Series not found.  You did not select a valid series for viewing.";
die;
}
$params = array(&$term);	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="Persistent Digital Archives and Library System" />
<title>PeDALS Web Administration</title>
<link rel="shortcut icon" href="images/favicon.ico" />
<link href="includes/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php include 'includes\header.php'; ?>
<div id="breadcrumb-container">
  <div id="breadcrumb"><a href="index.php" title="Home page">Home</a> / <a href="serSummary.php" title="Series">Series</a> / Series Detail</div>
  <div id="breadcrumb-side"><form name="search" action="search.php"><input type="text" name="q" width="50"/><input type="submit" value="Go" /></form><a href="advSearch.php" title="Advanced Search" alt="Advanced Search">Advanced Search</a>
  </div>
  <div class="clear"></div>
</div>
<!-- 
  CONTENT
  -->
<div id="content-container">
  <!-- 
	SIDE COLUMN
	-->
  <div id="content-side">
    <ul class="link-list-vertical">
      <li><a href="serSummary.php" title="View a list of all series in PeDALS.">List Series</a></li>
      <li><a href="serNew.php" title="Add a new series to PeDALS.">Add Series</a></li>
 <li><br/>
 	<li><?php echo "<a title=\"Edit\"";
		echo " alt=\"Edit\"";
		echo " href=serEdit.php?ser=".$term."";
		echo ">Edit this information</a><br/>";		
		?>
	<li><?php
		echo "<a title=\"Add Acquisition\"";
		echo " alt=\"Add Acquisition\"";
		echo " href=acqNew.php?ser=".$term."";
		echo ">Add Acquisition</a><br/>";		
		?>
    </ul>

  </div>
  <!-- 
	MAIN COLUMN
	-->
  <div id="content"><a name="maincontent" id="maincontent"></a>
 <?php 
$tsqlSer = "SELECT TOP 1 Series.SeriesId, Series.SeriesTitle, Series.SeriesDescription, Series.SeriesOpenDate, Series.SeriesStartYear, Series.SeriesEndYear, Series.SeriesDateRangeDescription, Series.SeriesExtentDescription, Series.SeriesArrangement, Series.SeriesRestrictionDescription, Series.SeriesGeneralNote, Series.SeriesIdentifier, Series.ProvenanceId, CONVERT(VARCHAR, Series.CreatedDate, 101) AS CreatedDate, Series.CreatedBy, CONVERT(VARCHAR, Series.ModifiedDate, 101) AS ModifiedDate, Series.ModifiedBy, Provenance.ProvenanceName FROM Series RIGHT OUTER JOIN Provenance ON Provenance.ProvenanceId = Series.ProvenanceId WHERE SeriesId = (?)";
 
 $getData = sqlsrv_prepare( $conn, $tsqlSer, $params);
 	if( $getData === false ) {
		 echo "Error in preparing statement.\n";
		 die( print_r( sqlsrv_errors(), true));
	}
	/* Execute the statement. Display any errors that occur. */
	if( sqlsrv_execute( $getData))
	{   
	/*echo "Statement executed.\n";*/
	}
	else
	{
		 echo "Error in executing statement.\n";
		 die( print_r( sqlsrv_errors(), true));
	}
	$rowCount = 0;
 	while (sqlsrv_fetch( $getData ))
	{	
		$id = sqlsrv_get_field($getData, 0);
		$title = sqlsrv_get_field($getData, 1);
		$opendate = sqlsrv_get_field($getData, 3);
		$startyear = sqlsrv_get_field($getData, 4);
		$endyear = sqlsrv_get_field($getData, 5);
		$daterange = sqlsrv_get_field($getData, 6);
		$extent = sqlsrv_get_field($getData, 7);
		$arrange = sqlsrv_get_field($getData, 8);
		$restrict = sqlsrv_get_field($getData, 9);
		$note = sqlsrv_get_field($getData, 10);
		$identifier = sqlsrv_get_field($getData, 11);
		$provid = sqlsrv_get_field($getData, 12);	
		$createdon = sqlsrv_get_field($getData, 13);
		$createdby = sqlsrv_get_field($getData, 14);
		$modifiedon = sqlsrv_get_field($getData, 15);
		$modifiedby = sqlsrv_get_field($getData, 16);
		$provname = sqlsrv_get_field($getData, 17);
		$rowCount++;
	}
	/* series id in query string is wrong */
	if( $rowCount == 0 ) { 
	echo "Series not found.  You did not select a valid series for viewing.<br/><br/><br/><br/>";
	die;
    	}
 ?>    
<h1><?php echo $title; ?></h1>
<p><strong>Provenance</strong>: <?php echo $provname; ?><br/>
<strong>Title</strong>: <?php echo $title; ?></p>
<p><strong>Identifier</strong>: <?php echo $identifier; ?></p> 
<p><strong>Date Range</strong>: <?php echo $daterange; ?><br/>
<strong>Start Year</strong>: <?php echo $startyear; ?><br/>
<strong>End Year</strong>: <?php echo $endyear; ?></p>
<p><strong>Extent</strong>: <?php echo $extent; ?><br/>
<strong>Arrangement</strong>: <?php echo $arrange; ?><br/>
<strong>Description</strong>: 
<?php 
$tsqlD = "SELECT SeriesDescription FROM Series WHERE SeriesId = (?)";
$stmt = sqlsrv_query( $conn, $tsqlD, $params);

while ($rr=sqlsrv_fetch_array($stmt, SQLSRV_FETCH_BOTH)){
	echo $rr[0];
}
 ?></p>
<p><strong>General Note</strong>:
<?php 
$tsqlN = "SELECT SeriesGeneralNote FROM Series WHERE SeriesId = (?)";
$stmt = sqlsrv_query( $conn, $tsqlN, $params);

while ($rr=sqlsrv_fetch_array($stmt, SQLSRV_FETCH_BOTH)){
	echo $rr[0];
}
 ?></p>     

<p><strong>Open Date</strong>: <?php echo $opendate; ?><br/>
<strong>Restriction Description</strong>: <?php echo $restrict; ?></p>      
<p><strong>Geographic Locations:</strong>
<?php 
$tsqlLoc = "SELECT GeoLocation.GeoLocationValue FROM  SeriesGeoLocation_LINK INNER JOIN GeoLocation ON SeriesGeoLocation_LINK.GeoLocationId = GeoLocation.GeoLocationId WHERE SeriesGeoLocation_LINK.SeriesId = (?) ORDER BY GeoLocation.GeoLocationValue";
 $getData = sqlsrv_prepare( $conn, $tsqlLoc, $params);
 	if( $getData === false ) {
		 echo "Error in preparing statement.\n";
		 die( print_r( sqlsrv_errors(), true));
	}
	/* Execute the statement. Display any errors that occur. */
	if( sqlsrv_execute( $getData))
	{   
	/*echo "Statement executed.\n";*/
	}
	else
	{
		 echo "Error in executing statement.\n";
		 die( print_r( sqlsrv_errors(), true));
	}
	$rowCount = 0;	
 	while (sqlsrv_fetch( $getData ))
	{	
		$location = sqlsrv_get_field($getData, 0);
		echo '<br/>';
		echo $location;
		$rowCount++;	
	}    
	if( $rowCount == 0 ) { 
	    echo "<tr><td colspan=\"2\"></td></tr>"; 
    	}
?>
</p>
<p><strong>Keywords:</strong>
<?php
 $tsqlKey = "SELECT SeriesKeyword FROM SeriesKeyword WHERE SeriesId = (?)";
 $getData = sqlsrv_prepare( $conn, $tsqlKey, $params);
 	if( $getData === false ) {
		 echo "Error in preparing statement.\n";
		 die( print_r( sqlsrv_errors(), true));
	}
	/* Execute the statement. Display any errors that occur. */
	if( sqlsrv_execute( $getData))
	{   
	/*echo "Statement executed.\n";*/
	}
	else
	{
		 echo "Error in executing statement.\n";
		 die( print_r( sqlsrv_errors(), true));
	}
	$rowCount = 0;	
 	while (sqlsrv_fetch( $getData ))
	{	
		$keyword = sqlsrv_get_field($getData, 0);
		echo '<br/>';
		echo $keyword;
		$rowCount++;	
	}    
	if( $rowCount == 0 ) { 
	    echo "<tr><td colspan=\"2\"></td></tr>"; 
    	}
?>
</p>
<p><strong>Subjects:</strong></p>

        <table class="table" border="1" cellspacing="0" summary="Table listing all subjecst for this series.">
      <thead>
        <tr>
          <th scope="col" width="30%">Qualifier</th>
          <th scope="col">Subject</th>
        </tr>
      </thead>
      <tbody>
<?php	
$tsqlSubj = "SELECT Qualifier.QualifierType, Subject.SubjectName FROM Subject INNER JOIN SeriesSubject_LINK ON Subject.SubjectId = SeriesSubject_LINK.SubjectId INNER JOIN Qualifier ON SeriesSubject_LINK.QualifierId = Qualifier.QualifierId WHERE     SeriesSubject_LINK.SeriesId = (?) ORDER BY Qualifier.QualifierType, Subject.SubjectName";
	/* Create the statement. */

	$getData = sqlsrv_prepare( $conn, $tsqlSubj, $params);
	if( $getData )
	{ 	}
	else
	{
		 echo "Error in preparing statement.\n";
		 die( print_r( sqlsrv_errors(), true));
	}

	/* Execute the statement. Display any errors that occur. */
	if( sqlsrv_execute( $getData))
	{ 	}
	else
	{
		 echo "Error in executing statement.\n";
		 die( print_r( sqlsrv_errors(), true));
	}
	$rowCount = 0;
	
	while (sqlsrv_fetch( $getData ))
	{
		$subQual = sqlsrv_get_field($getData, 0);
		$subName = sqlsrv_get_field($getData, 1);
		echo "<tr><td>".$subQual."</td><td>".$subName."</td></tr>";
		$rowCount++;
    }	

	
	if( $rowCount == 0 ) { 
	    echo "<tr><td colspan=\"2\">There are no subjects yet.</td></tr>"; 
    	}
	
?>
	</tbody>
	</table>
    <br/>
<p><strong>Acquisitions</strong>:<br/>
<?php
$tsqlAcq = "SELECT SeriesAcquisitionId, SeriesAcquisitionAccessionNumber, SeriesAcquisitionReadyToIngest AS rti FROM SeriesAcquisition WHERE SeriesId = (?) ORDER BY SeriesAcquisitionAccessionNumber";

	/* Create the statement. */
	$getData = sqlsrv_prepare( $conn, $tsqlAcq, $params);
	if( $getData )
	{ 	}
	else
	{
		 echo "Error in preparing statement.\n";
		 die( print_r( sqlsrv_errors(), true));
	}

	/* Execute the statement. Display any errors that occur. */
	if( sqlsrv_execute( $getData))
	{ 	}
	else
	{
		 echo "Error in executing statement.\n";
		 die( print_r( sqlsrv_errors(), true));
	}
	$rowCount = 0;
	
	while (sqlsrv_fetch( $getData ))
	{
		$id = sqlsrv_get_field($getData, 0);
		$identifier = sqlsrv_get_field($getData, 1);
		$status = sqlsrv_get_field($getData, 2);
		
		echo "<a title=\"".$identifier."\"";
		echo " alt=\"".$identifier."\"";
		echo " href=acqDetail.php?acq=".$id."";
		echo ">".$identifier."</a>";
	switch ($status) {
    case 0:
        echo "&nbsp;&nbsp;&nbsp;Status: Waiting for submission.<br/>";
        break;
    case 1:
        echo "&nbsp;&nbsp;&nbsp;Status: Accepted. BizTalk creating superpackage.<br/>";
        break;
    case 2:
        echo "&nbsp;&nbsp;&nbsp;Status: Rejected. BizTalk removing records.<br/>";
        break;
    case 3:
        echo "&nbsp;&nbsp;&nbsp;Status: Rejected at least once. Waiting for resubmission.<br/>";	
        break;		
    case 4:
        echo "&nbsp;&nbsp;&nbsp;Status: Ready for ingest by LOCKSS. Superpackage has been created.<br/>";	
        break;
    case 5:
        echo "&nbsp;&nbsp;&nbsp;Status: Ready for review.<br/>";
        break;
    case 9:
        echo "&nbsp;&nbsp;&nbsp;Status: BizTalk processing submitted records.<br/>";
        break;		
}
		$rowCount++;
    }	

	
	if( $rowCount == 0 ) { 
	    echo "There are no acquisitions for this series yet."; 
    	}
	
    sqlsrv_free_stmt( $getData );	
	sqlsrv_close( $conn);

?>              
</p>    
<p><strong>Actions</strong>:<br/>
<?php echo "<a title=\"Edit\"";
		echo " alt=\"Edit\"";
		echo " href=serEdit.php?ser=".$term."";
		echo ">Edit this information</a><br/>";		
		?>
        <?php
		echo "<a title=\"Add acquisition\"";
		echo " alt=\"Add acquisition\"";
		echo " href=acqNew.php?ser=".$term."";
		echo ">Add acquisition</a><br/>";		
		?>
        <?php
		echo "<a title=\"View provenance detail\"";
		echo " alt=\"View provenance detail\"";
		echo " href=provDetail.php?prov=".$provid."";
		echo ">View provenance detail</a><br/>";		
		?>          
        </p>

      <p><strong>Properties</strong>:<br/>
      Created by <?php echo $createdby; ?> on <?php echo $createdon; ?><br/>
      <?php
	  if ($modifiedby != "") {
      	echo "Modified by ".$modifiedby." on ".$modifiedon;
	  }
	?>
<?php include 'includes\footer.php'; ?>
  </div>

</div>
</body>
</html>
